import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot()
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4] )
#plt.show()
#plt.savefig('figure2.png', dpi=600)
#plt.savefig('figure2.svg', )
plt.savefig('figure3.pdf', )
plt.savefig('figure2.png')
plt.savefig('figure3.pdf', )
<Figure size 432x288 with 0 Axes>
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '.')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '.-')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='mediumblue')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='0')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='0.6')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')
ax.plot( [2,4] , [4,1], '-', c='red')
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '--', c='#53694e')
ax.plot( [2,4] , [4,1], '-', c='red', linewidth=3)
plt.show()
fig, ax = plt.subplots()
ax.plot( [1,2,4] , [3,5,4], '<', c='red')
ax.plot( [1,2,4] , [2,4,3], '>', c='blue')
plt.show()
import numpy as np
def f(x):
return x**2
X = np.linspace(-2, 2, 100)
Y = f(X)
fig, ax = plt.subplots()
ax.plot( X , Y, '.', c='red')
X
array([-2. , -1.95959596, -1.91919192, -1.87878788, -1.83838384,
-1.7979798 , -1.75757576, -1.71717172, -1.67676768, -1.63636364,
-1.5959596 , -1.55555556, -1.51515152, -1.47474747, -1.43434343,
-1.39393939, -1.35353535, -1.31313131, -1.27272727, -1.23232323,
-1.19191919, -1.15151515, -1.11111111, -1.07070707, -1.03030303,
-0.98989899, -0.94949495, -0.90909091, -0.86868687, -0.82828283,
-0.78787879, -0.74747475, -0.70707071, -0.66666667, -0.62626263,
-0.58585859, -0.54545455, -0.50505051, -0.46464646, -0.42424242,
-0.38383838, -0.34343434, -0.3030303 , -0.26262626, -0.22222222,
-0.18181818, -0.14141414, -0.1010101 , -0.06060606, -0.02020202,
0.02020202, 0.06060606, 0.1010101 , 0.14141414, 0.18181818,
0.22222222, 0.26262626, 0.3030303 , 0.34343434, 0.38383838,
0.42424242, 0.46464646, 0.50505051, 0.54545455, 0.58585859,
0.62626263, 0.66666667, 0.70707071, 0.74747475, 0.78787879,
0.82828283, 0.86868687, 0.90909091, 0.94949495, 0.98989899,
1.03030303, 1.07070707, 1.11111111, 1.15151515, 1.19191919,
1.23232323, 1.27272727, 1.31313131, 1.35353535, 1.39393939,
1.43434343, 1.47474747, 1.51515152, 1.55555556, 1.5959596 ,
1.63636364, 1.67676768, 1.71717172, 1.75757576, 1.7979798 ,
1.83838384, 1.87878788, 1.91919192, 1.95959596, 2. ])
import numpy as np
def f(x):
return x**2
X = np.linspace(-2, 2, 100)
Y = f(X)
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
[<matplotlib.lines.Line2D at 0x7fdf01bd86d0>]
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
(-3.0, 1.0)
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_ylim((1,3))
(1.0, 3.0)
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
Text(0.5, 1.0, 'Amazing results')
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
plt.show()
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
plt.show()
fig, ax = plt.subplots()
leg_1, = ax.plot( [1,2,4] , [3,5,4], '<', c='red')
#leg2, = ax.plot( [1,2,4] , [2,4,3], '>', c='blue')
# This is the same as:
leg_2 = ax.plot( [1,2,4] , [2,4,3], '>', c='blue')[0]
#ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
#ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
#ax.set_xticks([-2.5, -1, 0.5])
#ticks = ax.get_xticks().tolist()
#ticks[2] = "test"
#ax.set_xticklabels(ticks)
plt.legend([leg1, leg2], ['rats', 'mouse'], loc=4)
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
sns.set_theme()
sns.set_style('white')# ('dark') # ("whitegrid")
def f(x):
return x**2
X = np.linspace(-2, 2, 100)
Y = f(X)
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)
plt.show()
def f():
return [1]
a, = f()
print (a)
1
def f():
return [1,2]
a,b = f()
print (a,b)
1
def f():
return [1]
a, = f()
print (a)
1
def f():
return 1,2
a, = f()
print (a)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-60-21f0c826d110> in <module> 2 return (1,2) 3 ----> 4 a, = f() 5 print (a) ValueError: too many values to unpack (expected 1)
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)
ax.text(-1, 3, 'hello')
plt.show()
fig, ax = plt.subplots()
ax.plot( X , Y, '-', c='red')
ax.set_xlim((-3, 1))
ax.set_xlabel('Days')
ax.set_ylabel('Values')
ax.set_title('Amazing results', fontname="Comic Sans MS", fontsize=20)
ax.set_xticks([-2.5, -1, 0.5])
ticks = ax.get_xticks().tolist()
ticks[2] = "test"
ax.set_xticklabels(ticks)
#ax.grid(True)
ax.text(-1, 3, 'hello')
ax2 = ax.twinx()
ax2.plot([-2,-1, 0], [0.5, 1.5, 2.0])
plt.show()
fig, ax = plt.subplots(3,2)
ax[1][1].plot([1,5], [2,2], '-')
ax[2][0].plot(X, Y, '-')
[<matplotlib.lines.Line2D at 0x7fef6ade4160>]
fig, ax = plt.subplots(3)
fig, ax = plt.subplots(1,3)
import plotly.express as px
fig=px.line(
x=range(1,11),
y=[2,4,6,7,8,9,10,15,18,19],
labels={'x':'Day','y':'Number of new cases'})
fig.update_layout({'plot_bgcolor': '#d7dade','paper_bgcolor': '#d7dade'})
fig.show()
fig.write_html("file.html")